package com.kucowka.validators;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


public class CapitalizedValidator implements ConstraintValidator<Capitalized, Object> {

	private Capitalized constraintAnnotation;

	@Override
	public void initialize(Capitalized constraintAnnotation) {
		this.constraintAnnotation = constraintAnnotation;
	}

	@Override
	public boolean isValid(Object value, ConstraintValidatorContext context) {

		//context.disableDefaultConstraintViolation();

		//context.buildConstraintViolationWithTemplate(constraintAnnotation.message()).addNode("capitalized").addConstraintViolation();
		
		String text = (String) value;
		
		return text != null && text.length() > 0 && text.substring(0,1).toUpperCase().equals(text.substring(0, 1));
	}

}
